package com.code4j.ai.mcp.client.stdio;

import com.code4j.ai.mcp.client.sseMcp.SseService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/stdio")
public class AiController {

    @Autowired
    AiService aiService;
    ChatClient chatClient;

    public AiController(
                        ChatClient.Builder chatClientBuilder,
                        ToolCallbackProvider toolCallbackProvider) {
        chatClient=chatClientBuilder
                .defaultToolCallbacks(toolCallbackProvider)
                .build();
    }

    @RequestMapping("/chat")
    public String chat(@RequestParam(defaultValue = "查询分数") String message) {
        return chatClient.prompt().user(message).call().content();
    }


    @RequestMapping("/login")
    public String login(@RequestParam(defaultValue = "xushu")String username) throws Exception {

        aiService.changeMcp(username);
        return "success!";
    }
}
